package com.abigdreamer.swing.app;

import com.abigdreamer.swing.component.JCButton;
import craky.componentc.JCToggleButton;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractButton;

public class ButtonUtil
{
  public static List<AbstractButton> createJCToggleButtons(String[][] buttonInfos, Image normalImage, Image selImage, String actionCommand, ItemListener mgr)
  {
    List<AbstractButton> buttons = new ArrayList();
    String[][] arrayOfString = buttonInfos;int j = buttonInfos.length;
    for (int i = 0; i < j; i++)
    {
      String[] buttonInfo = arrayOfString[i];
      
      JCToggleButton btn = createJCToggleButton(buttonInfo[0], buttonInfo[1], normalImage, selImage, actionCommand, mgr);
      buttons.add(btn);
    }
    return buttons;
  }
  
  public static JCToggleButton createJCToggleButton(String text, String icon, Image normalImage, Image selImage, String actionCommand, ItemListener mgr)
  {
    JCToggleButton button = new JCToggleButton(text);
    button.setIcon(SwingUtil.getIcon(icon));
    
    button.setImage(normalImage);
    button.setRolloverImage(selImage);
    button.setSelectedImage(selImage);
    
    Dimension buttonSize = new Dimension(normalImage.getWidth(null), normalImage.getHeight(null));
    button.setPreferredSize(buttonSize);
    
    button.setFocusable(false);
    button.setVerticalTextPosition(3);
    button.setHorizontalTextPosition(0);
    button.setIconTextGap(0);
    
    button.setPaintPressDown(false);
    
    button.setActionCommand(actionCommand);
    
    button.addItemListener(mgr);
    
    return button;
  }
  
  public static JCButton createJCButton(String text, String icon, Image normalImage, Image selImage, String actionCommand, ActionListener mgr)
  {
    JCButton button = new JCButton(text);
    button.setIcon(SwingUtil.getIcon(icon));
    
    button.setImage(normalImage);
    button.setRolloverImage(selImage);
    button.setPressedImage(selImage);
    
    Dimension buttonSize = new Dimension(normalImage.getWidth(null), normalImage.getHeight(null));
    button.setPreferredSize(buttonSize);
    
    button.setFocusable(false);
    button.setVerticalTextPosition(3);
    button.setHorizontalTextPosition(0);
    button.setIconTextGap(0);
    
    button.setActionCommand(actionCommand);
    
    button.addActionListener(mgr);
    
    return button;
  }
}
